import { Injectable } from '@nestjs/common';
import { CreateMessageDto } from './dto/create-message.dto';
import { PrismaService } from '../prisma/prisma.service';

@Injectable()
export class MessageService {
  constructor(private readonly prismaService: PrismaService) {}
  async create(createMessageDto: CreateMessageDto) {
    console.log(createMessageDto);
    await this.prismaService.messageHistory.create({
      data: {
        chatRoomId: +createMessageDto.roomId,
        content: createMessageDto.content,
        userId: +createMessageDto.userId,
        type: createMessageDto.type,
      },
    });
  }

  async findAll(roomId: number) {
    return await this.prismaService.messageHistory.findMany({
      where: {
        chatRoomId: +roomId,
      },
      include: {
        user: {
          select: {
            username: true,
            id: true,
          },
        },
      },
    });
  }
}
